
package LwJGL;

import org.lwjgl.LWJGLException;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;

/**
 * InputExample.java
 * Created on May 3, 2014
 * Author Joe Porter
 */
public class InputExample {
    
    public void start(){
        try{
            Display.setDisplayMode(new DisplayMode(800, 600));
            Display.create();
        } catch(LWJGLException e){
            e.printStackTrace();
            System.exit(0);
        }
        
        while(!Display.isCloseRequested()){
            pollInput();
            Display.update();
        }
    }
    
    public void pollInput(){
        if (Mouse.isButtonDown(0)){
            int x = Mouse.getX();
            int y = Mouse.getY();
            
            System.out.println("MOUSE DOWN @ X: " + x + "Y: " + y);
        }
        if (Keyboard.isKeyDown((Keyboard.KEY_SPACE))){
            System.out.println("Space");
        }
        
        while(Keyboard.next()){
            if(Keyboard.getEventKeyState()){
                if(Keyboard.getEventKey() == Keyboard.KEY_A){
                System.out.println("A pressed");
                }
                if(Keyboard.getEventKey() == Keyboard.KEY_S){
                System.out.println("S pressed");
                }
                if(Keyboard.getEventKey() == Keyboard.KEY_D){
                System.out.println("D pressed");
                }
                if(Keyboard.getEventKey() == Keyboard.KEY_F){
                System.out.println("F pressed");
                }
            }else{
                if(Keyboard.getEventKey() == Keyboard.KEY_A){
                System.out.println("A released");
                }
                if(Keyboard.getEventKey() == Keyboard.KEY_S){
                System.out.println("S released");
                }
                if(Keyboard.getEventKey() == Keyboard.KEY_D){
                System.out.println("D released");
                }
                if(Keyboard.getEventKey() == Keyboard.KEY_F){
                System.out.println("F released");
                }
            }
        }
    }
    public static void main(String[] args){
        InputExample ie = new InputExample();
        ie.start();
    }
}
